//
//  AllCollectionViewController.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/24.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "AllCollectionViewController.h"
#import "LuBDefine.h"
#import "ZCXCollectViewController.h"
#import "AlbumViewController.h"
#import "LuBinCollectionViewController.h"
#import "ZCXVideoDetialViewController.h"
@interface AllCollectionViewController ()<LuBinCollectionViewControllerDelegate,ZCXCollectViewControllerDelegate>

@property (nonatomic, retain)UIScrollView *scrollView;

@property (nonatomic, retain)UISegmentedControl *segment;

@end

@implementation AllCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self createAllcollectionViewController];
    // Do any additional setup after loading the view.
}

- (void)createAllcollectionViewController{
    self.view.backgroundColor = [UIColor whiteColor];

    self.navigationItem.title = @"收藏";

    NSArray *array = @[@"视频收藏",@"相册收藏"];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.segment = [[UISegmentedControl alloc]initWithItems:array];
    self.segment.frame = CGRectMake(0, 64, CWIDTH, 35);
    self.segment.tintColor = [UIColor orangeColor];
    self.segment.selectedSegmentIndex = 0;
    [self.segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_segment];
    [_segment release];
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64 + 40 , CWIDTH, CHEIGHT - 64 - 40)];
    self.scrollView.contentSize = CGSizeMake(CWIDTH * 2, CHEIGHT - 64 - 40);

    self.scrollView.scrollEnabled = NO;
    self.scrollView.backgroundColor = [UIColor whiteColor];
    self.scrollView.showsHorizontalScrollIndicator = NO;

    self.scrollView.bounces = NO;
    self.scrollView.backgroundColor = [UIColor redColor];
    self.scrollView.scrollEnabled = NO;
    [self.view addSubview:_scrollView];
    [_scrollView release];
    
    ZCXCollectViewController *collect = [[ZCXCollectViewController alloc]init];
    collect.delegate = self;
    collect.view.frame = CGRectMake(0, 0, CWIDTH, CHEIGHT - 40 - 64);
    [_scrollView addSubview:collect.view];
    [self.scrollView addSubview:collect.view];
    
    LuBinCollectionViewController *lubinCollectionViewController = [[LuBinCollectionViewController alloc]init];
    lubinCollectionViewController.collectionDelegate = self;
    lubinCollectionViewController.view.frame = CGRectMake(CWIDTH, 0, CWIDTH, CHEIGHT - 64 - 40);
    [_scrollView addSubview:lubinCollectionViewController.view];
}

- (void)selectedAction:(LuBinCollection *)collection{
    AlbumViewController *albumViewController = [[AlbumViewController alloc]init];
    
    albumViewController.ppid = collection.ppid;
    albumViewController.photo_des = collection.photo_des;
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:albumViewController animated:YES];
    self.hidesBottomBarWhenPushed = NO;
    [albumViewController release];
}

- (void)segmentAction:(UISegmentedControl *)segment{
    if (segment.selectedSegmentIndex == 0){
        self.scrollView.contentOffset = CGPointMake(0, 0);
    }else if (segment.selectedSegmentIndex == 1){
        self.scrollView.contentOffset = CGPointMake(CWIDTH, 0);
    }
}
- (void)ZCXPushToVideo:(ZPetVideo *)PetVideo{
    ZCXVideoDetialViewController *video = [[ZCXVideoDetialViewController alloc]init];
    self.hidesBottomBarWhenPushed = YES;
    video.ID = [PetVideo videoID];
    UIBarButtonItem *backIetm = [[UIBarButtonItem alloc] init];
    backIetm.title =@"返回";
    self.navigationItem.backBarButtonItem = backIetm;
    [self.navigationController pushViewController:video animated:YES];
    [video release];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
